import React, { Component } from "react"
import "./index.css"
class Imported extends Component {
    constructor(props) {
        super(props)
        this.state = {
            cart: []
        }
    }
    async componentDidMount() {
        console.log("imported:", this.props.match.path)
        if (this.props.match.path == '/') {
            this.$bus.emit("change", true)
        }
        let res = (await this.$axios.get("http://127.0.0.1/React/app/server/getCart.php")).data
        this.setState(state => {
            state.cart = res
            return state
        })
    }
    render() {console.log("imported:",this.props)
        let lis = this.state.cart.map((ele, ind) => (
            <li key={ind}>
                <a href="#"><img src={'images/' + ele.c_img.split(",")[0]} /></a>
                <div className="dv">{ele.c_title}</div>
                <p><span>￥<i>{ele.c_price}</i></span>  <a href="javascript:;;" data-info={ele.c_id} onClick={()=>{this.props.history.push({pathname:'/Detail',state:{id:ele.c_id}})}}>购买</a></p>
            </li>
        ))
        return (
            <div className="Imp">
                <div className="dList">
                    <ul className="uList clearfloat">
                        {lis}
                    </ul>
                </div>

            </div>
        )
    }
}
export default Imported